import java.util.Stack;

public class Test1 {

}
class MyQueue {

    //栈实现队列
    Stack<Integer> stack1;
    Stack<Integer> stack2;

    public MyQueue() {
        stack1 = new Stack<>();
        stack2 = new Stack<>();
    }

    //尾插
    public void push(int x) {
        if (!stack1.empty()) {
            stack1.add(x);
        } else {
            stack2.add(x);
        }
    }

    //头删
    public int pop() {
        if (!stack2.empty()) {
            return stack2.pop();
        } else {
            in2out();
            return stack2.pop();
        }
    }

    //用于放入
    private void in2out() {
        while (stack1.size() > 0) {
            stack2.add(stack1.pop());
        }
    }

    //返回队列首元素
    public int peek() {
        if (!stack2.empty()) {
            return stack2.peek();
        } else {
            in2out();
            return stack2.peek();
        }
//判空

    }

    public boolean empty() {
        return stack1.empty() && stack2.empty();
    }
}